package com.hxci.liminshuo.controller;

import com.hxci.liminshuo.pojo.MinShuoUser;
import com.hxci.liminshuo.servcie.MinShuoUserServcie;  // 修正导入
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("minshuo/user")
public class MinShuoUserController {

    @RequestMapping("login")
    public String login(){
        return "liminshuo/login";
    }

    @Autowired
    private MinShuoUserServcie userServcie;  // 修正类型

    @ResponseBody
    @RequestMapping("tologin")
    public Integer tologin(HttpServletRequest request, @RequestParam("name") String name, @RequestParam("pass")String pass){
        System.out.println(name);
        System.out.println(pass);
        Integer res = userServcie.logion(name, pass, request);  // 修正方法调用
        return res;
    }
    // MinShuoUserController.java
    @ResponseBody
    @RequestMapping("current")
    public MinShuoUser getCurrentUser(HttpServletRequest request) {
        MinShuoUser user = (MinShuoUser) request.getSession().getAttribute("user");
        return user;
    }

    @RequestMapping("logout")
    public String logout(HttpServletRequest request) {
        request.getSession().invalidate();
        return "redirect:/minshuo/user/login";
    }

}
